// pages/detail/comDetail/comDetail.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    stars: [0, 1, 2, 3, 4],
    normalSrc: '../../../images/normal.png',
    selectedSrc: '../../../images/selected.png',
    bg:true,
    txt: [],
    keyq: 0,//评分
    keyw: 0,
    keye: 0,
    txt: [],
    cintx: [],
    uppic: [],
    id:[]
  },

  savetext: function (e) {


    var that = this;
    var inp = e.detail.value;

    that.setData({ txt: inp })
  },
  select1: function (e) {
    var that = this;
    console.log(e)
    var key = e.currentTarget.dataset.keyq



    console.log("左得" + key + "分")
    this.setData({
      keyq: key
    })

  },
  select2: function (e) {
    var that = this;
    console.log(e)
    var key = e.currentTarget.dataset.keyw



    console.log("左得" + key + "分")
    this.setData({
      keyw: key
    })

  },
  select3: function (e) {
    var that = this;
    console.log(e)
    var key = e.currentTarget.dataset.keye



    console.log("左得" + key + "分")
    this.setData({
      keye: key
    })

  },
  subcom: function () {
    var that = this;
    var openid = app.globalData.openid;
    var msg = this.data.txt;
    var object_id =that.data.id;
    var sheying = that.data.keyq;
    var zaoxing = that.data.keye;
    var fuwu = that.data.keyw;
    var tempFilePaths=that.data.uppic;
    wx.uploadFile({
      url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=assess', //仅为示例，非真实的接口地址
      filePath: tempFilePaths[0],
      name: 'file',
      formData: {
        msg: msg, openid: openid, object_id: object_id, sheying: sheying, zaoxing: zaoxing, fuwu: fuwu
      },
      success: function (res) {
        console.log(res);
        console.log(res.data);
        wx.switchTab({
          url: '../../index/index'
        })
    
      }
    }),

    console.log(openid)
    // wx.request({
    //   url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=assess',

    //   method: 'get',
    //   data: {
    //     msg: msg, openid: openid,object_id: object_id, sheying: sheying, zaoxing: zaoxing, fuwu: fuwu
    //   },
    //   header: {


    //     'content-type': 'application/json'
    //   },
    //   success(res) {
    //     console.log(res)
    //   }


    // })

  },



  comUpload: function () {
    var that=this;
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片


        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var tempFilePaths = res.tempFilePaths;
        that.setData({ 
          uppic: tempFilePaths,
           bg:false
        })

        console.log(tempFilePaths);
        console.log(tempFilePaths[0]);
        //上传图片
       
      }
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   var that=this;
   that.setData({
     id:options.id
   })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})